<?php

/**
 * Created by PhpStorm.
 * User: yellow
 * Date: 2017/6/28
 * Time: 10:46
 */

namespace Admin\Controller;

use Admin\Service\BannerService;

class BannerController extends BaseController {


    public function __construct() {
        parent::__construct();
        $this->bannerService = new BannerService();
        $type = array('1' => '小程序轮播图');
        $this->assign('Type',$type);
    }

    public function index() {
        $this->display();
    }
    public function ajax_index() {

        $nowPage = I('get.p', 1);
        $name = I('post.name', '');
        $type = I('post.type', '');

        $list = $this->bannerService->bannerList($name,$type,1);
        $page = $list['data'];

        $busConductList = $this->bannerService->bannerList($name,$type,0,$nowPage);

        $this->assign('page', $page->show());
        $this->assign('lists', $busConductList['data']);
        $this->display();
    }



    public function index_detail() {
        $id = I('get.id');
        $info = $this->bannerService->bannerInfo($id);
        $this->assign('info', $info);
        $this->assign('act','edit');
        $this->initEditor('banner');
        $this->display('add_banner');
    }


    public function add_banner() {
        $this->assign('act','add');
        $this->initEditor('banner');
        $this->display();
    }

    public function handle_banner() {
        if (IS_POST){

            $data = I('post.');
            $res = $this->bannerService->handleBanner($data);

            if ($res['code'] == 200 && $data['act'] != 'del'){

                $this->success('操作成功', U('Admin/banner/index'));
            } elseif($res['code'] != 200 && $data['act'] != 'del'){

                $this->error($res['msg'] ? $res['msg'] : '操作失败');
            } elseif ($data['act'] == 'del'){

                $this->ajaxReturn($res);
            }
        }
    }


}
